﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using System.Data;
using System.IO;
using System.Drawing;
public partial class administrator_uc_admin_e_user : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {        
        if (!IsPostBack)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["itemid"]))
            {                
                LoadDataInfo(Request.QueryString["itemid"].ToString());                
            }
        }
    }   
    private void LoadDataInfo(string ItemID)
    {
        DataTable dt = new BLL.CmsBLL().Manager_ViewItemByID(new Guid(ItemID));
        if (dt.Rows.Count > 0)
        {
            hdItemID.Value = dt.Rows[0]["ID"] + "";
            txtUserName.Text = dt.Rows[0]["UserName"].ToString();
            txtEmail.Text = dt.Rows[0]["Email"].ToString();
            txtFullName.Text = dt.Rows[0]["FullName"].ToString();
            txtAddress.Text = dt.Rows[0]["Address"].ToString();
            DropDownListDay.SelectedValue = Convert.ToDateTime(dt.Rows[0]["BirthDay"]).Day.ToString();
            DropDownListMonth.SelectedValue = Convert.ToDateTime(dt.Rows[0]["BirthDay"]).Month.ToString();
            txtYear.Text = Convert.ToDateTime(dt.Rows[0]["BirthDay"]).Year.ToString();
            rdSex.SelectedValue = dt.Rows[0]["Sex"].ToString();        
            
        }
        else
            lblMessage.Text = "Load data failt!";
    }    
    protected void lbtEditItem_Click(object sender, EventArgs e)
    {
        try
        {
            DateTime BirthDay = new DateTime();
            if (!string.IsNullOrEmpty(txtYear.Text))
                BirthDay = new DateTime(int.Parse("0" + txtYear.Text), int.Parse("0" + DropDownListMonth.SelectedValue), int.Parse("0" + DropDownListDay.SelectedValue));
            else BirthDay = DateTime.Now;           
            new CmsBLL().Manager_UpDateItemByUser(new Guid(hdItemID.Value), txtEmail.Text, txtFullName.Text, txtAddress.Text, BirthDay, int.Parse("0" + rdSex.SelectedValue));           
            lblMessage.Text = "Cập nhật thành công!";
        }
        catch (Exception ex)
        {
            lblMessage.Text = "ERROR! " + ex.Message.ToString();
        }
    }    
}